<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
            1. Promise构造函数：new Promise(executor)
                executor函数：是同步执行的，(resolve,reject)=>{}
                    resolve: 调用resolve可以让Promsie实例的状态由pending变为fulfilled(成功)
                    reject: 调用reject可以让promise实例的状态由pending变为rejected(失败)
                说明: executor函数会在Promise内部立即同步调用，异步代码放在executor中

            2. Promise.prototype.then方法: Promise实例.then(onFulfiled,onRejected)
                onFulfilled: 成功的回调函数 (value)=>{ }
                onRejected: 失败的回调函数 (reason)=>{ }
                特别注意(难点): then方法会返回一个新的Promise实例对象 
        */

        // 示例：then方法会返回一个新的Promise实例对象 
        const p = new Promise((resolve,reject)=>{
            setTimeout(() => {
                resolve(100)
            }, 1000);
        })

        const x = p.then(
            (res)=>{
                console.log(res)
                return res
            }
        )
        console.log(x);//发现是个promise示例
    </script>
</body>
</html>